import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2024-04-25
 * Time: 0:41.
 */
public class Test {

    public static void initOrder(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length - i;
        }
    }

    public static void noOrder(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(1_0000);
        }
    }

    public static void testInsert(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();

        Sort.insertSort(tmpArray);

        long endTime = System.currentTimeMillis();
        System.out.println("直接插入时间耗时:" + (endTime - startTime));
    }

    private static void testShellSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();

        Sort.shellSort(tmpArray);

        long endTime = System.currentTimeMillis();
        System.out.println("希尔时间耗时:" + (endTime - startTime));
    }

    private static void testSelectSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();

        Sort.selectSort(tmpArray);

        long endTime = System.currentTimeMillis();
        System.out.println("选择时间耗时:" + (endTime - startTime));
    }

    public static void main(String[] args) {
        int[] array = new int[1_0000];
        initOrder(array);
        testInsert(array);
        testShellSort(array);
        testSelectSort(array);
    }

    public static void main1(String[] args) {
        int[] array = {1,3,15,10,4,16,8};
        Sort.insertSort(array);
        System.out.println(Arrays.toString(array));

        System.out.println("==============================");

        int[] array2 = {1,3,15,10,4,16,8};
        Sort.shellSort(array2);
        System.out.println(Arrays.toString(array2));
    }
}
